package com.xdf.imoocdatav.service;

import com.xdf.imoocdatav.dao.cloud.DatavOrderuserMapper;
import com.xdf.imoocdatav.model.DatavOrderuser;
import com.xdf.imoocdatav.utils.BusinessException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DatavOrderuserServiceImpl implements DatavOrderuserService {

    @Autowired
    private DatavOrderuserMapper dao;

    /**
     * 这里需要转换两个字段：orderUserTrend 和 orderUserTrendAxis
     * 中的数字构成的字符串为数组返回给前端
     * @return
     */
    @Override
    public List<DatavOrderuser> selectAll() {
        List<DatavOrderuser> list = dao.selectAll();
        if( list.size()<=0 ) throw new BusinessException("未能从表 datav_orderuser 获取到数据！");
        String orderUserTrend = list.get(0).getOrderUserTrend();
        if( orderUserTrend == null || "".equals(orderUserTrend) || orderUserTrend.length()<=0)
            throw new BusinessException("orderUserTrend 为空，无法返回正常数据！");
        String orderUserTrendAxis = list.get(0).getOrderUserTrendAxis();
        if( orderUserTrendAxis == null || "".equals(orderUserTrendAxis) || orderUserTrendAxis.length()<=0 )
            throw new BusinessException("orderUserTrendAxis 为空，无法返回正常数据！");

        String[] orderUserTrends = orderUserTrend.split(",");
        String[] orderUserTrendAxises = orderUserTrendAxis.split(",");

        list.get(0).setOrderUserTrends(orderUserTrends);
        list.get(0).setOrderUserTrendAxises(orderUserTrendAxises);
        return list;
    }
}
